<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Test Android</title>
</head>
<script src="https://cdn.jsdelivr.net/npm/cdnbye@latest"></script>
<body>
<h3 id="h3"></h3>
<script>
    const isQQBrowser = /MQQBrowser/i.test(navigator.userAgent) && !/\sQQ/i.test(navigator.userAgent);
    if (isQQBrowser) {
        alert('QQ浏览器')
    }
    //
    // // QQ浏览器不支持MSE
    if (isMSESupported()) {
        alert('支持MSE')
    }

    if (isWebRTCSupported()) {
        alert('支持WebRTC')
    }

    function isMSESupported () {
        const mediaSource = getMediaSource();
        const sourceBuffer = window.SourceBuffer || window.WebKitSourceBuffer;
        const isTypeSupported = mediaSource &&
            typeof mediaSource.isTypeSupported === 'function' &&
            mediaSource.isTypeSupported('video/mp4; codecs="avc1.42E01E,mp4a.40.2"');

        // if SourceBuffer is exposed ensure its API is valid
        // safari and old version of Chrome doe not expose SourceBuffer globally so checking SourceBuffer.prototype is impossible
        const sourceBufferValidAPI = !sourceBuffer ||
            (sourceBuffer.prototype &&
                typeof sourceBuffer.prototype.appendBuffer === 'function' &&
                typeof sourceBuffer.prototype.remove === 'function');
        return !!isTypeSupported && !!sourceBufferValidAPI;
    }

    function isWebRTCSupported() {
        const browserRTC = getBrowserRTC();
        return (browserRTC && (browserRTC.RTCPeerConnection.prototype.createDataChannel !== undefined));
    }

    function getBrowserRTC () {
        if (typeof window === 'undefined') return null
        var wrtc = {
            RTCPeerConnection: window.RTCPeerConnection || window.mozRTCPeerConnection ||
                window.webkitRTCPeerConnection,
            RTCSessionDescription: window.RTCSessionDescription ||
                window.mozRTCSessionDescription || window.webkitRTCSessionDescription,
            RTCIceCandidate: window.RTCIceCandidate || window.mozRTCIceCandidate ||
                window.webkitRTCIceCandidate
        }
        if (!wrtc.RTCPeerConnection) return null
        return wrtc
    }

    function getMediaSource () {
        if (typeof window !== 'undefined') {
            return window.MediaSource || window.WebKitMediaSource;
        }
    }

    function getNetType() {
        let netType = ((new RegExp('nettype\\/(\\w*)').exec(_getUA()) || [, ''])[1]).toLowerCase();
        if (!netType && navigator.connection) {
            /*
                "bluetooth",
                "cellular",
                "ethernet",
                "mixed",
                "none",
                "other",
                "unknown",
                "wifi",
                "wimax"
             */
            const type = navigator.connection.type;
            switch (type) {
                case 'ethernet':
                    netType = 'ethernet';
                    break;
                case 'cellular':
                    netType = '4g';
                    break;
                default:
                    netType = 'wifi'
            }
        }
        return netType;
    }

    let net = getNetType();
    if (!net) net = 'wifi'

    document.getElementById('h3').innerText = net

    function _getUA() {
        return navigator.userAgent.toLowerCase();
    }


</script>
</body>
</html>
